package model
import java.util.{Date}
import play.api.db._
import anorm._
import anorm.SqlParser._
import play.api.Play.current

case class p_Page_Control(controlId:Int,
                          clientId:String,
                          content: String,
                          PageId: Int,
                          LanguageId: Int,
                          InsertTime: Date,
                          ChangeTime: Option[Date],
                          IsDeleted: Boolean)
object p_Page_Control {
  val parser = {
      get[Int]("Control_ID") ~
      get[String]("Client_ID") ~
      get[String]("Content") ~
      get[Int]("Page_ID") ~
      get[Int]("Language_ID") ~
      get[Date]("InsertTime") ~
      get[Option[Date]]("ChangeTime") ~
      get[Boolean]("IsDeleted") map {
        case a ~ b ~ c ~ d ~ e ~ f ~ g ~ h =>
          p_Page_Control(a, b, c, d, e, f, g, h)
      }
  }

  def getByClientId(clientId: String) : p_Page_Control = {
    DB.withConnection { implicit connection =>
          //SELECT * FROM "P_Page_Control" where "Client_ID" = 'ddd'
          SQL("SELECT *  FROM \"P_Page_Control\" WHERE \"Client_ID\" = {c}").on('c -> clientId)
          .as(p_Page_Control.parser.single)
        }
      } 
  
  def update(clientId: String, content: String) ={
    DB.withConnection { implicit connection =>
          //SELECT * FROM "P_Page_Control" where "Client_ID" = 'ddd'
          SQL("UPDATE \"P_Page_Control\" SET \"Content\" = {content} WHERE \"Client_ID\" = {c}").on('c -> clientId,'content -> content)
          .executeUpdate()
        }
  }
}

